using UnityEngine;

public class KineticServeMoveElement : KineticElementMove
{
	public class MoveConstraint
	{
		public enum Direction
		{
			XDir = 0,
			YDir = 1,
			ZDir = 2
		}

		public Direction direction;

		public bool doConstrain;

		public bool constrainThroughtoutAnim;

		public float position;
	}

	public MoveConstraint xMoveConstraint = new MoveConstraint();

	public MoveConstraint yMoveConstraint = new MoveConstraint();

	public MoveConstraint zMoveConstraint = new MoveConstraint();

	public override void OnAnimatorMove()
	{
		if (base.animator == null)
		{
			return;
		}
		AnimatorStateInfo currentAnimatorStateInfo = base.animator.GetCurrentAnimatorStateInfo(0);
		if (currentAnimatorStateInfo.shortNameHash == Animator.StringToHash(animInfo.animatorStateName) && isActive)
		{
			float num = base.ellapsedTime;
			base.ellapsedTime += Time.deltaTime * animatorSpeed;
			base.ellapsedRealTime += Time.deltaTime;
			KineticAnimationInfo.CheckpointInfo nextCheckpointInfo = GetNextCheckpointInfo(num);
			if (nextCheckpointInfo != null && nextCheckpointInfo.time < base.ellapsedTime)
			{
				CalculateCheckpointErorr(nextCheckpointInfo, num, base.ellapsedTime);
			}
			float value = base.ellapsedTime / animInfo.clipLength;
			float t = animInfo.adjustmentsTimeWindow.InverseLerp(value);
			if (useSmoothStep)
			{
				t = Mathf.SmoothStep(0f, 1f, t);
			}
			Quaternion quaternion = Quaternion.Lerp(Quaternion.identity, Quaternion.AngleAxis(adjustAngle, Vector3.up), t);
			positionChange += Quaternion.Inverse(quaternion) * base.animator.deltaPosition;
			rotationChange = base.animator.deltaRotation * rotationChange;
			position = startPosition + positionChange + AdjustPosition();
			position.x = ((!xMoveConstraint.doConstrain || !xMoveConstraint.constrainThroughtoutAnim) ? position.x : xMoveConstraint.position);
			position.y = ((!yMoveConstraint.doConstrain || !yMoveConstraint.constrainThroughtoutAnim) ? position.y : yMoveConstraint.position);
			position.z = ((!zMoveConstraint.doConstrain || !zMoveConstraint.constrainThroughtoutAnim) ? position.z : zMoveConstraint.position);
			rotation = quaternion * rotationChange * startRotation;
			UpdateCharacterTransform();
			if ((currentAnimatorStateInfo.normalizedTime >= 1f && !base.animator.IsInTransition(0)) || base.ellapsedTime + crossFadeDuration * animatorSpeed >= animInfo.clipLength)
			{
				EndAnimation();
			}
		}
	}

	public override void EndAnimation()
	{
		position.x = ((!xMoveConstraint.doConstrain) ? position.x : xMoveConstraint.position);
		position.y = ((!yMoveConstraint.doConstrain) ? position.y : yMoveConstraint.position);
		position.z = ((!zMoveConstraint.doConstrain) ? position.z : zMoveConstraint.position);
		base.EndAnimation();
	}

	public void UpdatePosition(Vector3 positionToAdd)
	{
		startPosition += positionToAdd;
		position += positionToAdd;
		xMoveConstraint.position += positionToAdd.x;
		yMoveConstraint.position += positionToAdd.y;
		zMoveConstraint.position += positionToAdd.z;
	}
}
